package com.abi${classpath}.enums;

import com.abi.icircle.common.api.DefaultApiCode;
import com.abi.icircle.common.api.exception.ApiException;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.EnumSet;
import java.util.Set;

/**
 * ${enumDesc}
 * @Author AndyTan
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ${enumName_Iii}Enum {

	//${enumDesc}: ${enumItem}
	<#list enumItemList as temp>
	ITEM_${temp.t0_iii}(${temp.t0_iii},"${temp.t1_iii}")<#if temp_has_next>,<#else >;</#if>
	</#list>

	@EnumValue
	private Integer code;
	private String name;

	private static final Set<${enumName_Iii}Enum> ALL = EnumSet.allOf(${enumName_Iii}Enum.class);

    public static String getName(Integer code) {
        return ALL.stream()
                .filter(o -> o.code.equals(code))
                .map(o -> o.getName())
                .findAny().orElse(null);
    }

    public static Integer getCode(String name) {
        return ALL.stream()
                .filter(o -> o.name.equals(name))
                .map(o -> o.getCode())
                .findAny().orElse(null);
    }

	public boolean is(Integer code){
		return getCode().equals(code);
	}

}
